<!doctype html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>LiteAdmin 后台登录</title>
    {include file="public/main_head"}
</head>
<body class="login-bg">

<div class="login">
    <div class="message">LiteAdmin 1.0 后台登录</div>
    <div id="darkbannerwrap"></div>

    <form class="layui-form" action="{:url('admin/login/login')}" method="post">
        <input name="username" placeholder="用户名" type="text" lay-verify="required" class="layui-input" value="">
        <hr class="hr15">
        <input name="password" lay-verify="required" placeholder="密码" type="password" class="layui-input" value="">
        <hr class="hr15">
        <input name="verify" lay-verify="required" placeholder="验证码" type="text" class="layui-input" value="">
        <hr class="hr15">
        <img id="captcha" src="{:captcha_src()}" onclick="verify_reload()" style="border: 1px solid;border-radius: 3px; border-color: rgb(220, 222, 224);" >
        <span onclick="verify_reload()" style="text-decoration:underline ">点击验证码刷新</span>
        <hr class="hr15">
        <input value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">
        <hr class="hr20">
    </form>
</div>

<script>
    /**
     * 刷新验证码
     */
    function verify_reload(){
        $("#captcha").attr('src','{:captcha_src()}?'+(new Date()).getTime())
    }

    $(function () {
        if (top.location.href !== window.location.href){
            top.location.href = window.location.href
        }
        layui.use('form', function () {
            var form = layui.form;
            //监听提交
            form.on('submit(login)', function (data) {
                var url = $(data.elem).attr('action');
                $.post(url,data.field).fail(function (xmr) {
                    layui.layer.msg("网络错误，status = "+xmr.status,{shade: [0.3, '#393D49'],icon: data.code,time: 3000,shadeClose:true});
                }).then(function (data) {
                    layui.layer.msg(data.msg,
                        {
                            shade: [0.3, '#393D49'],
                            icon: data.code,
                            time: data.wait*1000,
                            shadeClose:true
                        },
                        function () {
                            if (data.code){
                                location.href = data.url;
                            }else{
                                verify_reload();
                            }
                        }
                    );
                });
                return false;
            });
        });
    })
</script>
</body>
</html>